{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Title: #Check if Strings Can be Made Equal With Operations I"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Difficulty: #Easy"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Category Title: #Algorithms"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Tag Slug: #string"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Name Translated: #字符串"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solution Name: canBeEqual"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Title: #判断通过操作能否让字符串相等 I"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Content:\n",
    "<p>给你两个字符串&nbsp;<code>s1</code> 和&nbsp;<code>s2</code>&nbsp;，两个字符串的长度都为&nbsp;<code>4</code>&nbsp;，且只包含 <strong>小写</strong> 英文字母。</p>\n",
    "\n",
    "<p>你可以对两个字符串中的 <strong>任意一个</strong>&nbsp;执行以下操作 <strong>任意</strong>&nbsp;次：</p>\n",
    "\n",
    "<ul>\n",
    "\t<li>选择两个下标&nbsp;<code>i</code> 和&nbsp;<code>j</code>&nbsp;且满足&nbsp;<code>j - i = 2</code>&nbsp;，然后 <strong>交换</strong> 这个字符串中两个下标对应的字符。</li>\n",
    "</ul>\n",
    "\n",
    "<p>如果你可以让字符串<em>&nbsp;</em><code>s1</code><em> </em>和<em>&nbsp;</em><code>s2</code>&nbsp;相等，那么返回 <code>true</code>&nbsp;，否则返回 <code>false</code>&nbsp;。</p>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong class=\"example\">示例 1：</strong></p>\n",
    "\n",
    "<pre>\n",
    "<b>输入：</b>s1 = \"abcd\", s2 = \"cdab\"\n",
    "<b>输出：</b>true\n",
    "<strong>解释：</strong> 我们可以对 s1 执行以下操作：\n",
    "- 选择下标 i = 0 ，j = 2 ，得到字符串 s1 = \"cbad\" 。\n",
    "- 选择下标 i = 1 ，j = 3 ，得到字符串 s1 = \"cdab\" = s2 。\n",
    "</pre>\n",
    "\n",
    "<p><strong class=\"example\">示例 2：</strong></p>\n",
    "\n",
    "<pre>\n",
    "<b>输入：</b>s1 = \"abcd\", s2 = \"dacb\"\n",
    "<b>输出：</b>false\n",
    "<b>解释：</b>无法让两个字符串相等。\n",
    "</pre>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>提示：</strong></p>\n",
    "\n",
    "<ul>\n",
    "\t<li><code>s1.length == s2.length == 4</code></li>\n",
    "\t<li><code>s1</code> 和&nbsp;<code>s2</code>&nbsp;只包含小写英文字母。</li>\n",
    "</ul>\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Description: [check-if-strings-can-be-made-equal-with-operations-i](https://leetcode.cn/problems/check-if-strings-can-be-made-equal-with-operations-i/description/)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solutions: [check-if-strings-can-be-made-equal-with-operations-i](https://leetcode.cn/problems/check-if-strings-can-be-made-equal-with-operations-i/solutions/)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "test_cases = ['\"abcd\"\\n\"cdab\"', '\"abcd\"\\n\"dacb\"']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canBeEqual(self, s1: str, s2: str) -> bool:\n",
    "        return set([s1[0], s1[2]]) == set([s2[0], s2[2]]) and set([s1[1], s1[3]]) == set([s2[1], s2[3]])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canBeEqual(self, s1: str, s2: str) -> bool:\n",
    "        return set(s1[0::2]) == set(s2[0::2]) and set(s1[1::2]) == set(s2[1::2])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canBeEqual(self, s1: str, s2: str) -> bool:\n",
    "        def is_eq(s1,s2,p1):\n",
    "            a = [s1[p1],s1[p1+2]]\n",
    "            b = [s2[p1],s2[p1+2]]\n",
    "            a.sort()\n",
    "            b.sort()\n",
    "            for aa,bb in zip(a,b):\n",
    "                if aa != bb:\n",
    "                    # print(aa,bb)\n",
    "                    return False\n",
    "            return True\n",
    "        return is_eq(s1,s2,0) and is_eq(s1,s2,1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canBeEqual(self, s1: str, s2: str) -> bool:\n",
    "        return Counter(s1[::2]) == Counter(s2[::2]) and Counter(s1[1::2]) == Counter(s2[1::2])\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canBeEqual(self, s1: str, s2: str) -> bool:\n",
    "        a = sorted(s1[0] + s1[2])\n",
    "        b = sorted(s1[1] + s1[3])\n",
    "        c = sorted(s2[0] + s2[2])\n",
    "        d = sorted(s2[1] + s2[3])\n",
    "        return a == c and b == d "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canBeEqual(self, s1: str, s2: str) -> bool:\n",
    "        if s1 == s2 :\n",
    "            return True\n",
    "        if s1[0] + s1[1] + s1[2] + s1[3] == s2[0] + s2[3] + s2[2] + s2[1] :\n",
    "            return True\n",
    "        if s1[0] + s1[1] + s1[2] + s1[3] == s2[2] + s2[1] + s2[0] + s2[3] :\n",
    "            return True\n",
    "        if s1[0] + s1[1] + s1[2] + s1[3] == s2[2] + s2[3] + s2[0] + s2[1] :\n",
    "            return True\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canBeEqual(self, s1: str, s2: str) -> bool:\n",
    "        return s1==s2 or (((s1[0]==s2[2] and s1[2]==s2[0]) or (s1[0]==s2[0] and s1[2]==s2[2])) and ((s1[1]==s2[3] and s1[3]==s2[1]) or (s1[1]==s2[1] and s1[3]==s2[3])))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canBeEqual(self, s1: str, s2: str) -> bool:\n",
    "        return str(sorted(s1[::2])) == str(sorted(s2[::2])) and str(sorted(s1[1::2])) == str(sorted(s2[1::2]))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canBeEqual(self, s1: str, s2: str) -> bool:\n",
    "        s1_1 = list(s1[0::2])\n",
    "        s1_2 = list(s1[1::2])\n",
    "        s2_1 = list(s2[0::2])\n",
    "        s2_2 = list(s2[1::2])\n",
    "        s1_1.sort()  \n",
    "        s2_1.sort()  \n",
    "        s1_2.sort()  \n",
    "        s2_2.sort()  \n",
    "        if s1_1 == s2_1 and s1_2 == s2_2:\n",
    "            return True\n",
    "        else:\n",
    "            return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canBeEqual(self, s1: str, s2: str) -> bool:\n",
    "        return {s1[0], s1[2]} == {s2[0], s2[2]} and {s1[1], s1[3]} == {s2[1], s2[3]}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canBeEqual(self, s1: str, s2: str) -> bool:\n",
    "        if s1 == s2:\n",
    "            return True\n",
    "        if s1[0] == s2[2] and s1[2] == s2[0] and s1[1] == s2[1] and s1[3] == s2[3]:\n",
    "            return True\n",
    "        if s1[0] == s2[0] and s1[2] == s2[2] and s1[1] == s2[3] and s1[3] == s2[1]:\n",
    "            return True\n",
    "        if s1[0] == s2[2] and s1[2] == s2[0] and s1[1] == s2[3] and s1[3] == s2[1]:\n",
    "            return True\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canBeEqual(self, s1: str, s2: str) -> bool:\n",
    "        s1 = list(s1)\n",
    "        s2 = list(s2)\n",
    "        if s1 == s2: return True\n",
    "        s1[1],s1[3] = s1[3],s1[1]\n",
    "        if s1 == s2: return True\n",
    "        s1[0],s1[2] = s1[2],s1[0]\n",
    "        if s1 == s2: return True\n",
    "        s1[1],s1[3] = s1[3],s1[1]\n",
    "        if s1 == s2: return True\n",
    "        return False\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canBeEqual(self, s1: str, s2: str) -> bool:\n",
    "        n = len(s1)\n",
    "        for i, word in enumerate(s1):\n",
    "            if word != s2[i] and word != s2[(i + 2) % n]:\n",
    "                return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canBeEqual(self, s1: str, s2: str) -> bool:\n",
    "        if s1==s2:\n",
    "            return True\n",
    "\n",
    "        def func(s1,s2,i):\n",
    "            j=i+2\n",
    "            \n",
    "            if s1[i]==s2[j] and s2[i]==s1[j]:\n",
    "                return True\n",
    "            elif s1[i]==s2[i] and s1[j]==s2[j]:\n",
    "                return True\n",
    "            else:\n",
    "                return False\n",
    "\n",
    "        return func(s1,s2,0) and func(s1,s2,1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canBeEqual(self, s1: str, s2: str) -> bool:\n",
    "        return Counter(s1[::2]) == Counter(s2[::2]) and Counter(s1[1::2]) == Counter(s2[1::2])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canBeEqual(self, s1: str, s2: str) -> bool:\n",
    "        return sorted(s1[::2]) == sorted(s2[::2]) and sorted(s1[1::2]) == sorted(s2[1::2])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canBeEqual(self, s1: str, s2: str) -> bool:\n",
    "        s1_odd = sorted([s1[0], s1[2]])\n",
    "        s1_even = sorted([s1[1], s1[3]])\n",
    "        s2_odd = sorted([s2[0], s2[2]])\n",
    "        s2_even = sorted([s2[1], s2[3]])\n",
    "\n",
    "        if s1_odd == s2_odd and s1_even == s2_even:\n",
    "            return True\n",
    "        else:\n",
    "            return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "from collections import Counter\n",
    "\n",
    "class Solution:\n",
    "    def canBeEqual(self, s1: str, s2: str) -> bool:\n",
    "        return Counter(s1[::2]) == Counter(s2[::2]) and Counter(s1[1::2]) == Counter(s2[1::2])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canBeEqual(self, s1: str, s2: str) -> bool:\n",
    "        s1_even_counter = Counter(s1[::2])\n",
    "        s2_even_counter = Counter(s2[::2])\n",
    "        s1_odd_counter = Counter(s1[1::2])\n",
    "        s2_odd_counter = Counter(s2[1::2])\n",
    "        if s1_even_counter == s2_even_counter and s1_odd_counter == s2_odd_counter:\n",
    "            return True \n",
    "        else:\n",
    "            return False "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canBeEqual(self, s1: str, s2: str) -> bool:\n",
    "        s1_odd = sorted([s1[0], s1[2]])\n",
    "        s1_even = sorted([s1[1], s1[3]])\n",
    "        s2_odd = sorted([s2[0], s2[2]])\n",
    "        s2_even = sorted([s2[1], s2[3]])\n",
    "\n",
    "        if s1_odd == s2_odd and s1_even == s2_even:\n",
    "            return True\n",
    "        else:\n",
    "            return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canBeEqual(self, s1: str, s2: str) -> bool:\n",
    "        return Counter(s1[::2]) == Counter(s2[::2]) and Counter(s1[1::2]) == Counter(s2[1::2])\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canBeEqual(self, s1: str, s2: str) -> bool:\n",
    "        if s1 == s2:\n",
    "            return True\n",
    "        else:\n",
    "            s1 = s1[2] + s1[1] + s1[0] + s1[3]\n",
    "            if s1 == s2:\n",
    "                return True\n",
    "            else:\n",
    "                s1 = s1[0] + s1[3] + s1[2] + s1[1]\n",
    "                if s1 == s2:\n",
    "                    return True\n",
    "                else:\n",
    "                    s1 = s1[2] + s1[1] + s1[0] + s1[3]\n",
    "                    if s1 == s2:\n",
    "                        return True\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canBeEqual(self, s1: str, s2: str) -> bool:\n",
    "        return Counter(s1[::2]) == Counter(s2[::2]) and Counter(s1[1::2]) == Counter(s2[1::2])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canBeEqual(self, s1: str, s2: str) -> bool:\n",
    "        s1_odd = sorted([s1[0], s1[2]])\n",
    "        s1_even = sorted([s1[1], s1[3]])\n",
    "        s2_odd = sorted([s2[0], s2[2]])\n",
    "        s2_even = sorted([s2[1], s2[3]])\n",
    "\n",
    "        if s1_odd == s2_odd and s1_even == s2_even:\n",
    "            return True\n",
    "        else:\n",
    "            return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canBeEqual(self, s1: str, s2: str) -> bool:\n",
    "        return ((s1[0] == s2[0] and s1[2] == s2[2]) or (s1[0] == s2[2] and s1[2] == s2[0])) and ((s1[1] == s2[1] and s1[3] == s2[3]) or (s1[1] == s2[3] and s1[3] == s2[1]))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canBeEqual(self, s1: str, s2: str) -> bool:\n",
    "        js1 = s1[0]+s1[2]\n",
    "        os1 = s1[1]+s1[3]\n",
    "\n",
    "        js2 = s2[0]+s2[2]\n",
    "        # print(js2.count(s1[0]), js2.count(s1[2]))\n",
    "        if js2.count(s1[0])==0 or js2.count(s1[2])==0:\n",
    "            return False\n",
    "\n",
    "        os2 = s2[1]+s2[3]\n",
    "        if os2.count(s1[1])==0 or os2.count(s1[3])==0:\n",
    "            return False\n",
    "        \n",
    "        return True\n",
    "\n",
    "        # # 根据下标奇偶性分类\n",
    "        # js1 = s1[0]+s1[2]\n",
    "        # os1 = s1[1]+s1[3]\n",
    "\n",
    "        # js2 = s2[0]+s2[2]\n",
    "        # js2f = s2[2]+s2[0]\n",
    "\n",
    "        # os2 = s2[1]+s2[3]\n",
    "        # os2f = s2[3]+s2[1]\n",
    "\n",
    "        # # 比较\n",
    "        # if js1==js2 or js1==js2f:\n",
    "        #     pass\n",
    "        # else :\n",
    "        #     return False\n",
    "\n",
    "        # if os1==os2 or os1==os2f:\n",
    "        #     pass\n",
    "        # else :\n",
    "        #     return False\n",
    "        \n",
    "        # return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canBeEqual(self, s1: str, s2: str) -> bool:\n",
    "        \n",
    "        return Counter(s1[::2]) == Counter(s2[::2]) and Counter(s1[1::2]) == Counter(s2[1::2])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canBeEqual(self, s1: str, s2: str) -> bool:\n",
    "        return (sorted(s1[0]+s1[2]) == sorted(s2[0]+s2[2]) and sorted(s1[1]+s1[3]) == sorted(s2[1]+s2[3]))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canBeEqual(self, s1: str, s2: str) -> bool:\n",
    "        return Counter(s1[::2]) == Counter(s2[::2]) and Counter(s1[1::2]) == Counter(s2[1::2])\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canBeEqual(self, s1: str, s2: str) -> bool:\n",
    "        a1 = ''.join(sorted([s1[0],s1[2]])) + ''.join(sorted([s1[1],s1[3]]))\n",
    "        a2 = ''.join(sorted([s2[0],s2[2]])) + ''.join(sorted([s2[1],s2[3]]))\n",
    "        return a1==a2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canBeEqual(self, s1: str, s2: str) -> bool:\n",
    "        return Counter(s1[::2]) == Counter(s2[::2]) and Counter(s1[1::2]) == Counter(s2[1::2])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canBeEqual(self, s1: str, s2: str) -> bool:\n",
    "        return Counter(s1[::2]) == Counter(s2[::2]) and Counter(s1[1::2]) == Counter(s2[1::2])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canBeEqual(self, s1: str, s2: str) -> bool:\n",
    "        return sorted(s1[::2]) == sorted(s2[::2]) and sorted(s1[1::2]) == sorted(s2[1::2])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canBeEqual(self, s1: str, s2: str) -> bool:\n",
    "        ls = list(s2)\n",
    "        for i in range(2):\n",
    "            if s1[i] != ls[i]:\n",
    "                if s1[i] == ls[i + 2]:\n",
    "                    ls[i + 2], ls[i] = ls[i], s2[i + 2]\n",
    "                else:\n",
    "                    return False\n",
    "        return s1 == \"\".join(ls)\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "\n",
    "    def canBeEqual(self, s1: str, s2: str) -> bool:\n",
    "\n",
    "        return Counter(s1[::2]) == Counter(s2[::2]) and Counter(s1[1::2]) == Counter(s2[1::2])\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canBeEqual(self, s1: str, s2: str) -> bool:\n",
    "        return Counter(s1[::2]) == Counter(s2[::2]) and Counter(s1[1::2]) == Counter(s2[1::2])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "# 交换一次和交换多次本质一样\n",
    "class Solution:\n",
    "    def canBeEqual(self, s1: str, s2: str) -> bool:\n",
    "        if s1 == s2:\n",
    "            return True\n",
    "\n",
    "        def func(s1,s2,i):\n",
    "            j = i+2\n",
    "\n",
    "            if s1[i] == s2[j] and s2[i] == s1[j]:\n",
    "                return True\n",
    "\n",
    "            if s1[i] == s2[i] and s2[j] == s1[j]:\n",
    "                return True\n",
    "\n",
    "            return False\n",
    "\n",
    "        return func(s1,s2,0) and func(s1,s2,1)\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canBeEqual(self, s1: str, s2: str) -> bool:\n",
    "    # 先判断一开始是否相等\n",
    "        if s1 == s2:\n",
    "            return True\n",
    "    # 不一致\n",
    "        temp = 0\n",
    "        lst1 = list(s1)   #转成数组\n",
    "        lst2 = list(s2)\n",
    "        for i in range(len(lst1)-2):\n",
    "            j = i+2\n",
    "            if lst1[i] == lst2[i] and lst1[j] == lst2[j]:\n",
    "                continue   #如果此时两个列表对应位置相同，不交换\n",
    "            else:  \n",
    "                if j<len(lst1):  #j不出界时执行交换\n",
    "                    temp = lst1[i]\n",
    "                    lst1[i] = lst1[j]\n",
    "                    lst1[j] = temp\n",
    "            s11 = ''.join(lst1)  #转换成字符串比较\n",
    "            if s11 == s2:   # 如果相等返回真\n",
    "                return True\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canBeEqual(self, s1: str, s2: str) -> bool:\n",
    "        return sorted(s1[::2]) == sorted(s2[::2]) and sorted(s1[1::2]) == sorted(s2[1::2])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canBeEqual(self, s1: str, s2: str) -> bool:\n",
    "        ls1,rs1 = list(s1[0::2]),list(s1[1::2])\n",
    "        ls2,rs2 = list(s2[0::2]),list(s2[1::2])\n",
    "        \n",
    "        ls1.sort()\n",
    "        ls2.sort()\n",
    "        rs1.sort()\n",
    "        rs2.sort()\n",
    "        if ls1==ls2 and rs1==rs2 : return True\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canBeEqual(self, s1: str, s2: str) -> bool:\n",
    "        return Counter(s1[::2])==Counter(s2[::2]) and Counter(s1[1::2])==Counter(s2[1::2])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canBeEqual(self, s1: str, s2: str) -> bool:\n",
    "        return Counter(s1[::2])==Counter(s2[::2]) and Counter(s1[1::2])==Counter(s2[1::2])\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canBeEqual(self, s1: str, s2: str) -> bool:\n",
    "        return ((s1[0]==s2[0] and s1[2]==s2[2]) or (s1[0]==s2[2] and s1[2]==s2[0])) and ((s1[1]==s2[1] and s1[3]==s2[3]) or (s1[1]==s2[3] and s1[3]==s2[1]))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canBeEqual(self, s1: str, s2: str) -> bool:\n",
    "        return s1 == s2 or s1[2] + s1[1] + s1[0] + s1[3] == s2 or s1[0] + s1[3] + s1[2] + s1[1] == s2 or s1[2] + s1[3] + s1[0] + s1[1] == s2 \n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canBeEqual(self, s1: str, s2: str) -> bool:\n",
    "        ans = []\n",
    "        ans.append(s1) \n",
    "        # 2 \n",
    "        ans.append(s1[2] + s1[1] + s1[0] + s1[3])\n",
    "        ans.append(s1[0] + s1[3] + s1[2] + s1[1])\n",
    "        ans.append(s1[2] + s1[3] + s1[0] + s1[1])\n",
    "        return s2 in ans "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canBeEqual(self, s1: str, s2: str) -> bool:\n",
    "        return collections.Counter(s1[::2])==collections.Counter(s2[::2]) and collections.Counter(s1[1::2])==collections.Counter(s2[1::2])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canBeEqual(self, s1: str, s2: str) -> bool:\n",
    "        if s1 == s2:\n",
    "            return True\n",
    "        s1, s2 = list(s1), list(s2)\n",
    "        s11, s12 = s1[:], s1[:]\n",
    "        s11[0], s11[2] = s11[2], s11[0]\n",
    "        s12[1], s12[3] = s12[3], s12[1]\n",
    "        s13 = s11[:]\n",
    "        s13[1], s13[3] = s13[3], s13[1]\n",
    "        if s11 == s2 or s12 == s2 or s13 == s2:\n",
    "            return True\n",
    "\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canBeEqual(self, s1: str, s2: str) -> bool:\n",
    "        s1_odd = sorted([s1[0], s1[2]])\n",
    "        s1_even = sorted([s1[1], s1[3]])\n",
    "        s2_odd = sorted([s2[0], s2[2]])\n",
    "        s2_even = sorted([s2[1], s2[3]])\n",
    "\n",
    "        if s1_odd==s2_odd and s1_even==s2_even:\n",
    "            return True\n",
    "        else:\n",
    "            return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canBeEqual(self, s1: str, s2: str,res = True) -> bool:\n",
    "        for i in range(2):\n",
    "            if set([s1[i],s1[i+2]]) != set([s2[i],s2[i+2]]):\n",
    "                return False\n",
    "        return res "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canBeEqual(self, s1: str, s2: str) -> bool:\n",
    "        hashmap1 = Counter()\n",
    "        hashmap2 = Counter()\n",
    "        hashmap3 = Counter()\n",
    "        hashmap4 = Counter()\n",
    "        for i in range(0, len(s1)-1, 2):\n",
    "            hashmap1[s1[i]] += 1\n",
    "            hashmap2[s2[i]] += 1\n",
    "        for j in range(1, len(s1), 2):\n",
    "            hashmap3[s1[j]] += 1\n",
    "            hashmap4[s2[j]] += 1\n",
    "        return hashmap1 == hashmap2 and hashmap3 == hashmap4"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canBeEqual(self, s1: str, s2: str) -> bool:\n",
    "        t1 = s1[0]+s1[2]\n",
    "        t2 = s1[1]+s1[3]\n",
    "        c1 = s2[0]+s2[2]\n",
    "        c2 = s2[1]+s2[3]\n",
    "\n",
    "        if (t1==c1 or t1==c1[::-1]) and (c2==t2 or c2==t2[::-1]):\n",
    "            return True\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canBeEqual(self, s1: str, s2: str) -> bool:\n",
    "        s1_odd = sorted([s1[0], s1[2]])\n",
    "        s1_even = sorted([s1[1], s1[3]])\n",
    "        s2_odd = sorted([s2[0], s2[2]])\n",
    "        s2_even = sorted([s2[1], s2[3]])\n",
    "\n",
    "        if s1_odd == s2_odd and s1_even == s2_even:\n",
    "            return True\n",
    "        else:\n",
    "            return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canBeEqual(self, s1: str, s2: str) -> bool:\n",
    "        s1 = list(s1)\n",
    "        if s1[0] > s1[2]:\n",
    "            s1[2], s1[0] = s1[0], s1[2]\n",
    "        if s1[1] > s1[3]:\n",
    "            s1[3], s1[1] = s1[1], s1[3]\n",
    "        s2 = list(s2)\n",
    "        if s2[0] > s2[2]:\n",
    "            s2[2], s2[0] = s2[0], s2[2]\n",
    "        if s2[1] > s2[3]:\n",
    "            s2[3], s2[1] = s2[1], s2[3]            \n",
    "        return ''.join(s1) == ''.join(s2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canBeEqual(self, s1: str, s2: str) -> bool:\n",
    "        if not ((s1[0]==s2[0] and s1[2]==s2[2]) or (s1[0]==s2[2] and s1[2]==s2[0])):\n",
    "            return False\n",
    "\n",
    "        if not ((s1[1]==s2[1] and s1[3]==s2[3]) or (s1[1]==s2[3] and s1[3]==s2[1])):\n",
    "            return False\n",
    "\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canBeEqual(self, s1: str, s2: str) -> bool:\n",
    "        if s1 == s2:\n",
    "            return True\n",
    "        return set([s1[0],s1[2]])==set([s2[0],s2[2]]) and set([s1[1],s1[3]])==set([s2[1],s2[3]])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canBeEqual(self, s1: str, s2: str) -> bool:\n",
    "        return s1[0] in (s2[0],s2[2]) and s1[2] in (s2[0],s2[2]) and s1[1] in (s2[1],s2[3]) and s1[3] in (s2[1],s2[3])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canBeEqual(self, s1: str, s2: str) -> bool:\n",
    "        t1=list(s1)\n",
    "        t2=list(s2)\n",
    "        t1_2=[t1[2]]+[t1[1]]+[t1[0]]+[t1[3]]\n",
    "        t1_3=[t1[0]]+[t1[3]]+[t1[2]]+[t1[1]]\n",
    "        t1_4=[t1[2]]+[t1[3]]+[t1[0]]+[t1[1]]\n",
    "        if t1==t2:\n",
    "            return True\n",
    "        elif t1_2==t2:\n",
    "            return True\n",
    "        elif t1_3==t2:\n",
    "            return True\n",
    "        elif t1_4==t2:\n",
    "            return True\n",
    "        else:\n",
    "            return False\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canBeEqual(self, s1: str, s2: str) -> bool:\n",
    "        # return s1[0] in (s2[0],s2[2]) and s1[2] in (s2[0],s2[2]) and s1[1] in (s2[1],s2[3]) and s1[3] in (s2[1],s2[3])\n",
    "        return set([s1[0],s1[2]]) == set([s2[0],s2[2]]) and set([s1[1],s1[3]]) == set([s2[1],s2[3]])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canBeEqual(self, s1: str, s2: str) -> bool:\n",
    "    # 先判断一开始是否相等\n",
    "        if s1 == s2:\n",
    "            return True\n",
    "    # 不一致\n",
    "        temp = 0\n",
    "        lst1 = list(s1)   #转成数组\n",
    "        lst2 = list(s2)\n",
    "        for i in range(len(lst1)-2):\n",
    "            j = i+2\n",
    "            if lst1[i] == lst2[i] and lst1[j] == lst2[j]:\n",
    "                continue   #如果此时两个列表对应位置相同，不交换\n",
    "            else:  \n",
    "                if j<len(lst1):  #j不出界时执行交换\n",
    "                    temp = lst1[i]\n",
    "                    lst1[i] = lst1[j]\n",
    "                    lst1[j] = temp\n",
    "            s11 = ''.join(lst1)  #转换成字符串比较\n",
    "            if s11 == s2:   # 如果相等返回真\n",
    "                return True\n",
    "            # elif lst1[i] == lst2[i] and lst1[j] == lst2[j]:   #不等，可能是前半相同后半不同的情况\n",
    "            #     lst1[i], lst1[j] = lst1[j], lst1[i]  # 当交换，恢复原始顺序\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canBeEqual(self, s1: str, s2: str) -> bool:\n",
    "      list1 = [list(s1)[0], list(s1)[2]]\n",
    "      list2 = [list(s2)[0], list(s2)[2]]\n",
    "      list3 = [list(s1)[1], list(s1)[3]]\n",
    "      list4 = [list(s2)[1], list(s2)[3]]\n",
    "      list1.sort()\n",
    "      list2.sort()\n",
    "      list3.sort()\n",
    "      list4.sort()\n",
    "      if list1[0] == list2[0] and list1[1] == list2[1] and list3[0] == list4[0] and list3[1] == list4[1]:\n",
    "          return True\n",
    "      else:\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canBeEqual(self, s1: str, s2: str) -> bool:\n",
    "        s1_odd = s1[0::2]\n",
    "        s2_odd = s2[0::2]\n",
    "        s1_even = s1[1::2]\n",
    "        s2_even = s2[1::2]\n",
    "        return set(s1_even) == set(s2_even) and set(s1_odd) == set(s2_odd)\n",
    "\n",
    "\n",
    "if __name__ == '__main__':\n",
    "    pass\n",
    "    print(Solution.canBeEqual(None, \"abcd\", \"dacb\"))\n",
    "    pass\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canBeEqual(self, s1: str, s2: str) -> bool:\n",
    "        return Counter(s1[::2])==Counter(s2[::2]) and Counter(s1[1::2])==Counter(s2[1::2])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canBeEqual(self, s1: str, s2: str) -> bool:\n",
    "        ls1=list(s1)\n",
    "        ls2=list(s2)\n",
    "        if ls1 == ls2:\n",
    "            return True\n",
    "        if ls1[0] != ls2[0]:\n",
    "            ls1[2],ls1[0]=ls1[0],ls1[2]\n",
    "        if ls1 == ls2:\n",
    "            return True\n",
    "        if ls1[1] != ls2[1]:\n",
    "            ls1[1],ls1[3]=ls1[3],ls1[1]\n",
    "        return ls1 == ls2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canBeEqual(self, s1: str, s2: str) -> bool:\n",
    "        return {s1[0], s1[2]} == {s2[0], s2[2]} and {s1[1], s1[3]} == {s2[1], s2[3]}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canBeEqual(self, s1: str, s2: str) -> bool:\n",
    "\n",
    "        if s1 == s2:\n",
    "            return True\n",
    "\n",
    "        def fun(s1, s2, i):\n",
    "            j = i + 2\n",
    "            if s1[i] == s2[j] and s2[i] == s1[j]:\n",
    "                return True\n",
    "            if s1[i] == s2[i] and s1[j] == s2[j]:\n",
    "                return True\n",
    "            return False\n",
    "\n",
    "        return fun(s1,s2,0) and fun(s1,s2,1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canBeEqual(self, s1: str, s2: str) -> bool:\n",
    "        return s1[0] in (s2[0],s2[2]) and s1[2] in (s2[0],s2[2]) and s1[1] in (s2[1],s2[3]) and s1[3] in (s2[1],s2[3])\n",
    "        # return set([s1[0],s1[2]]) == set([s2[0],s2[2]]) and set([s1[1],s1[3]]) == set([s2[1],s2[3]])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canBeEqual(self, s1: str, s2: str) -> bool:\n",
    "        a,b,c,d = s1[0], s1[1], s1[2], s1[3]\n",
    "        e,f,g,h = s2[0], s2[1], s2[2], s2[3]\n",
    "        i = (a==e and c==g) or (a==g and c==e)\n",
    "        j = (b==f and d==h) or (b==h and d==f)\n",
    "        return i and j"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canBeEqual(self, s1: str, s2: str) -> bool:\n",
    "    # 先判断一开始是否相等\n",
    "        if s1 == s2:\n",
    "            return True\n",
    "    # 不一致\n",
    "        lst1 = list(s1)   #转成数组\n",
    "        lst2 = list(s2)\n",
    "        for i in range(len(lst1)-2):\n",
    "            j = i+2\n",
    "            if lst1[i] == lst2[i] and lst1[j] == lst2[j]:\n",
    "                continue   #如果此时两个列表对应位置相同，不交换\n",
    "            else:  \n",
    "                if j<len(lst1):  #j不出界时执行交换\n",
    "                    lst1[i], lst1[j] = lst1[j], lst1[i]\n",
    "            s11 = ''.join(lst1)    #转换成字符串比较\n",
    "            if s11 == s2:        # 如果相等返回真\n",
    "                return True\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canBeEqual(self, s1: str, s2: str) -> bool:\n",
    "        cnt1 = Counter()\n",
    "        cnt2 = Counter()\n",
    "        for i in range(4):\n",
    "            r = (i+2)%4\n",
    "            if s1[i]!=s2[r] and s1[i]!=s2[i]:\n",
    "                return False\n",
    "            cnt1[s1[i]]+=1\n",
    "            cnt2[s2[i]]+=1\n",
    "        if cnt1==cnt2:\n",
    "            return True\n",
    "        else:\n",
    "            return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canBeEqual(self, s1: str, s2: str) -> bool:\n",
    "        if s1==s2:\n",
    "            return True\n",
    "        s=s1[2]+s1[1]+s1[0]+s1[3]\n",
    "        ss=s1[0]+s1[3]+s1[2]+s1[1]\n",
    "        if s==s2 or ss==s2:\n",
    "            return True\n",
    "        elif not s1[0]+s1[3]+s1[2]+s1[1]==s2 and ss[2]+ss[1]+ss[0]+ss[3]==s2:\n",
    "            return True\n",
    "        elif not  s1[2]+s1[1]+s1[0]+s1[3]==s2 and s[0]+s[3]+s[2]+s[1]==s2:\n",
    "            return True\n",
    "        else:\n",
    "            return False      "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canBeEqual(self, s1: str, s2: str) -> bool:\n",
    "        if s1[0] == s2[0] and s1[2] == s2[2]:\n",
    "            if s1[1] == s2[1] and s1[3] == s2[3]:\n",
    "                return True\n",
    "            elif s1[1] == s2[3] and s1[3] == s2[1]:\n",
    "                return True\n",
    "            else:\n",
    "                return False\n",
    "        elif s1[2] == s2[0] and s1[0] == s2[2]:\n",
    "            if s1[1] == s2[1] and s1[3] == s2[3]:\n",
    "                return True\n",
    "            elif s1[1] == s2[3] and s1[3] == s2[1]:\n",
    "                return True\n",
    "            else:\n",
    "                return False\n",
    "        else:\n",
    "            return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canBeEqual(self, s1: str, s2: str) -> bool:\n",
    "        odd1 = []\n",
    "        odd2 = []\n",
    "        even1 = []\n",
    "        even2 = []\n",
    "        for i in range(len(s1)):\n",
    "            if i % 2:\n",
    "                odd1.append(s1[i])\n",
    "            else:\n",
    "                even1.append(s1[i])\n",
    "        for i in range(len(s2)):\n",
    "            if i % 2:\n",
    "                odd2.append(s2[i])\n",
    "            else:\n",
    "                even2.append(s2[i])\n",
    "        odd1 = sorted(odd1)\n",
    "        odd2 = sorted(odd2)\n",
    "        even1 = sorted(even1)\n",
    "        even2 = sorted(even2)\n",
    "        for i in range(len(odd1)):\n",
    "            if odd1[i] != odd2[i]:\n",
    "                return False\n",
    "        for i in range(len(even1)):\n",
    "            if even1[i] != even2[i]:\n",
    "                return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canBeEqual(self, s1: str, s2: str) -> bool:\n",
    "        a=sorted([s1[0],s1[2]])\n",
    "        b=sorted([s1[1],s1[-1]])\n",
    "        c=sorted([s2[0],s2[2]])\n",
    "        d=sorted([s2[1],s2[-1]])\n",
    "        return all(a[i]==c[i] for i in range(2)) and all(b[i]==d[i] for i in range(2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canBeEqual(self, s1: str, s2: str) -> bool:\n",
    "        # return s1[0] in (s2[0],s2[2]) and s1[2] in (s2[0],s2[2]) and s1[1] in (s2[1],s2[3]) and s1[3] in (s2[1],s2[3])\n",
    "        return set([s1[0],s1[2]]) == set([s2[0],s2[2]]) and set([s1[1],s1[3]]) == set([s2[1],s2[3]])"
   ]
  }
 ],
 "metadata": {},
 "nbformat": 4,
 "nbformat_minor": 2
}
